//#define DEBUG
#include <cstdio>
#include <algorithm>

#define INC(x, y) (x=(x+(y))%mods)

using namespace std;

typedef long long ll;

const int maxn=50000, mods=1000000007;

class Tree {
    public:
        int n, m, ind[maxn+1], to[2*maxn-1], link[2*maxn-1], s[maxn+1], size[maxn+1];
        bool vis[maxn+1];

        void addSide(int u, int v) {
            m++;
            to[m] = v;
            link[m] = ind[u];
            ind[u] = m;
        }

        ll solve1() {           // k==1
            ll ret=0;
            for (int i=1; i<=n; i++) {
                INC(ret, s[i]);
            }
            return ret;
        }

        ll solve2() {       // k==2
            ll ret=0;
            for (int i=1; i<=n; i++) {
                for (int j=ind[i]; j; j=link[j]) {
                    if (to[j]>i) {
                        INC(ret, s[i]);
                    }
                }
            }
            return ret;
        }

        int getCentroid(int o, int fa, int tot) {
            bool flag=true;
            int ret=n+1;
            size[o] = 1;
            for (int i=ind[o]; i; i=link[i]) {
                if (vis[to[i]] && to[i]!=fa) {
                    ret = min(ret, getCentroid(to[i], o, tot));
                    size[o] += size[to[i]];
                    flag = flag && size[to[i]]<=tot/2;
                }
            }
            flag = flag && tot-size[o]<=tot/2;
            return flag ? min(ret, o) : ret;
        }

        ll count(int o, int last, int k) {
            ll ans=0;
            if (o<=k) {
                for (int i=last+1; i<=n; i++) {
                    vis[i] = true;
                    INC(ans, count(o+1, i, k));
                    vis[i] = false;
                }
            } else {
                ans = s[getCentroid(last, 0, k)];
                if (size[last]!=k) {
                    ans = 0;
                }
            }
            return ans;
        }

        ll solve3(int k) {           // n<=20
            return count(1, 0, k);
        }
};

int main() {
    freopen("centroid.in", "r", stdin);
    freopen("checker.out", "w", stdout);

    static Tree g;
    int n, k;
    scanf("%d %d", &n, &k);
    g.n = n;
    for (int i=1; i<=n; i++) {
        scanf("%d", g.s+i);
    }
    for (int i=1; i<n; i++) {
        int x, y;
        scanf("%d %d", &x, &y);
        g.addSide(x, y), g.addSide(y, x);
    }

    ll ans;
    if (k==1) {
        ans=g.solve1();
    } else if (k==2) {
        ans=g.solve2();
    } else {
        ans=g.solve3(k);
    }
    printf("%lld\n", ans);

    fclose(stdin);
    fclose(stdout);
    return 0;
}
